from pathlib import Path
from typing import Protocol

from fastapi import UploadFile

from common.oss_storage import OSSStorage


class FileStorage(Protocol):
	async def save(self, file: UploadFile, destination: Path) -> None: ...


class LocalFileStorage(FileStorage):
	async def save(self, file: UploadFile, destination: Path):
		with destination.open("wb") as f:
			while chunk := await file.read(1024 * 1024):
				f.write(chunk)


# file_storage: FileStorage = LocalFileStorage()
file_storage = OSSStorage()
